<template>
	<div>
		<DetailPage :key="reloadForm" v-bind="ExtendDetailConfig" :borderBottom="true" :model="formModel" style="width: 98%; margin: 0 auto">
			<template v-slot:dp_foundation_social_title="{ row }">
				<ApldTable :columns="row.column" :data="formModel.dp_foundation_social_title"></ApldTable>
			</template>
		</DetailPage>
	</div>
</template>

<script setup lang="ts">
import { ApldTable } from '@/components/AplidCrud'
import apiMod from '@/apiMod'
import DetailPage from '@/views/aplid/DetailPage/index.vue'
import { ExtendDetailConfig } from '../../config'
import { useCommonStore } from '@/stores/common'
const { setLoading } = useCommonStore()

const rowData: any = inject('nowRowData')

const props = defineProps({
	chainViewInfo:{
		type:Object,
		default:()=>({})
	},
	isBlockchain:{
		type:Boolean,
		default:false
	}
})

const formModel:any = ref({
	dp_practitioners_experience: [],
	dp_training_record: [],
	dp_subsidy_info: [],
	dp_reward_punishment_info: [],
	dp_foundation_social_title: [],
})

const reloadForm = ref(0)

const getInitData = () => {
	const query = { idCard: rowData.idCard }
	setLoading()

	Promise.all([apiMod.view_dpFoundationPractitionersExtend_page(query), apiMod.view_dpFoundationSocialTitle_page(query)])
		.then((res) => {
			return res.map((item) => item.data.records)
		})
		.then((res) => {
			formModel.value = {
				...(res[0][0] || {}),
				dp_foundation_social_title: res[1],
			}
			reloadForm.value = Math.random()
			setLoading()
		}).catch(()=> {
      setLoading()
    })
}

onMounted(() => {
	if(props.isBlockchain){
		formModel.value = props.chainViewInfo
		formModel.value.dp_foundation_social_title = props.chainViewInfo.bcFoundationSocialTitle?JSON.parse(props.chainViewInfo.bcFoundationSocialTitle):[]
	}else{
		getInitData()
	}
})
</script>

<style scoped></style>
